#include<stdio.h>
#include<stdlib.h>

#define eleType int

typedef struct {
    eleType *elements;
    size_t front;
    size_t rear;
    size_t capacity;
} Queue;

void QueueCreate( Queue *q ){
    q -> elements = (eleType *)malloc(sizeof(eleType) * 10);
    q -> front = q -> rear = 0;
    q -> capacity = 10;
}

void QueueDestroy(Queue *q){
    free(q -> elements);
    q -> front = 0;
    q -> rear = 0;
    q -> capacity = 0;
    q -> elements = NULL;

}

void QueueResize(Queue *q){
    eleType *newElements = (eleType *)realloc(q->elements, sizeof(eleType) * ( q->capacity * 2 ) );)
    if(newElements == NULL){
        q->elements = newElements;
        q->capacity *= 2;
}

void QueuePush(Queue *q, eleType e){
    if(q -> rear == q -> capacity){
        QueueResize(q);
    }
    q -> elements[q -> rear++] = e;
     
}

eleType QueuePop(Queue *q){

    if(q -> front == q -> rear){
        printf("队列为空\n");
        exit(-1);
    }
    return q -> elements[q -> front++];
}
eleType QueueFront(Queue *q){
    if(q -> front == q -> rear){
        printf("队列为空\n");
        exit(-1);
    }
    return q ->   elements[q -> front++];
}
